package cn.edu.nuc.onlinestore.frame;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import cn.edu.nuc.onlinestore.Person.Admin;

import cn.edu.nuc.onlinestore.Person.ObjectStream;
import cn.edu.nuc.onlinestore.network.TCPClient;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Map;
import java.awt.event.ActionEvent;

public class userCheckOut extends JFrame {

	private JPanel contentPane;
	private JTextField usernameField;
	private JPasswordField passwordField;
	private JFrame frame;
	private JFrame parentFrame;
	/**
	 * Launch the application.
	 */
/*	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					userCheckOut frame = new userCheckOut();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	/**
	 * Create the frame.
	 */
	public userCheckOut(JFrame parentFrame,DefaultTableModel model,String name) {
		this.parentFrame = parentFrame;
		this.frame = this;
		setTitle("中北线在商场管理系统-用户结账");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 425, 252);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel label = new JLabel("卡号:");
		label.setBounds(76, 54, 54, 15);
		contentPane.add(label);

		JLabel label_1 = new JLabel("密  码:");
		label_1.setBounds(76, 96, 54, 15);
		contentPane.add(label_1);

		usernameField = new JTextField();
		usernameField.setBounds(140, 51, 139, 21);
		contentPane.add(usernameField);
		usernameField.setColumns(10);

		passwordField = new JPasswordField();
		passwordField.setBounds(140, 93, 139, 21);
		contentPane.add(passwordField);

		JButton button = new JButton("完成交易");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
                String msg="checkMoney###"+name;
                
                String result=new TCPClient().send(msg);
                
                if("success".equals(result)){
                	JOptionPane.showMessageDialog(null, "交易成功！");
                	UserStore.totalCount=0;
                	frame.setVisible(false);
    				parentFrame.setVisible(false);
                }else{
                	JOptionPane.showMessageDialog(null, "交易失败！");
                }
				
				
			}
		});
		button.setBounds(163, 146, 93, 23);
		contentPane.add(button);

		JLabel lblNewLabel = new JLabel("");
	    lblNewLabel.setBounds(208, 54, 86, 82);
		contentPane.add(lblNewLabel);
	}
}
